package org.banxico.dgef.etasaho.bean;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;


public class JobLog {
	private static final int MAX_NUMREG_LOG = 100;
	
	public static final String TIPO_INFO    = "INFO";
	public static final String TIPO_WARNING = "WARNING";
	public static final String TIPO_FATAL   = "FATAL";
	public static final String TIPO_REJECT  = "REJECT";
	public static final String TIPO_CONTROL = "STARTED";
	public static final String TIPO_RESET   = "RESET";
	public static final String TIPO_RUNJOB  = "BATCH";
	public static final String TIPO_ANY     = "ANY";
	
	private int maxNumeroRegistrosLog = 10;
	private String tipoLog;
	private Map<Integer, LogElement> dsLog;
	
	
	public JobLog() {
		if ( this.dsLog == null ) this.dsLog = new TreeMap<Integer, LogElement>();
	}

	public int getMaxNumeroRegistrosLog() {
		return maxNumeroRegistrosLog;
	}

	public void setMaxNumeroRegistrosLog(int maxNumeroRegistrosLog) {
		this.maxNumeroRegistrosLog = (maxNumeroRegistrosLog > MAX_NUMREG_LOG) ? MAX_NUMREG_LOG : maxNumeroRegistrosLog;
	}

	public String getTipoLog() {
		return tipoLog;
	}

	public void setTipoLog(String tipoLog) {
		this.tipoLog = tipoLog;
	}
	
	public void addLogEntry(Integer entry, LogElement element) {
		this.dsLog.put(entry, element);
	}
	
	public Set<Integer> obtieneEntries() {
		return this.dsLog.keySet();
	}
	
	public String obtieneMensajeLog(int entryID) {
		return this.dsLog.containsKey(entryID) ? this.dsLog.get(entryID).getMensaje() : null;
	}
	
	public LogElement getLogElement(int entryID) {
		return this.dsLog.containsKey(entryID) ? this.dsLog.get(entryID) : null;
	}
	
	public void imprimeDSLog() {
		if(this.dsLog != null) {
			for (Entry<Integer, LogElement> entry : this.dsLog.entrySet()) {
				System.out.println("Llave: " + entry.getKey() + ", Valor: " + entry.getValue());
			}
		}
	}
	
}
